package org.xukai.common.util;

import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

/**
 * @author xukai
 * @desc
 * @date 2016-09-11-下午 1:38
 */
public class SystemPropertiesUtil {

        public static Map<String, String> setSystemProperties(Properties properties) {
            HashMap ret = new HashMap();
            Iterator var3 = properties.entrySet().iterator();

            while(var3.hasNext()) {
                Map.Entry entry = (Map.Entry)var3.next();
                String key = (String)entry.getKey();
                String oldValue = System.getProperty(key);
                String value = (String)entry.getValue();
                if(oldValue != null && !StringUtils.pathEquals(oldValue, value)) {
                    throw new IllegalStateException("the system property already set to different value: \'" + key + "\'" + " = [" + oldValue + "] instead of [" + value + "]");
                }

                System.setProperty(key, value);
                ret.put(key, value);
            }

            return ret;
        }

        public static void removeSystemProperties(Properties properties) {
            Iterator var2 = properties.entrySet().iterator();

            while(var2.hasNext()) {
                Map.Entry entry = (Map.Entry)var2.next();
                String key = (String)entry.getKey();
                System.getProperties().remove(key);
            }

        }
}
